package com.bawei.module_home.ui.area

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.lib_common.utils.ToastUtils
import com.bawei.module_home.R
import com.bawei.module_home.databinding.ActivityAreaDetailBinding
import com.bawei.module_home.http.HomeServiceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.AREA_DETAIL_PAGE)
class AreaDetailActivity : BaseActivity<HomeServiceViewModel, ActivityAreaDetailBinding>() {
    @Autowired(name = "areaId")
    @JvmField
    var areaId: Int=0
    override val mLayoutResId: Int
        get() = R.layout.activity_area_detail

    private val mViewModel: HomeServiceViewModel by viewModels()
    override fun initView() {
        super.initView()


    }

    override fun initData() {
        mViewModel.AreaDetail(areaId)
    }

    override fun initListener() {
        mViewModel.detailAreaState.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    ToastUtils.showLong(this,"获取成功")
                    mBinding.name.text=mViewModel.areaDetailItem.value?.areaName
                }
            }
        }
    }

}